#pragma once

#include <Windows.h>
#include <memory>

class SharedMemory {
public:

	typedef HANDLE Handle;
	static const Handle kInvalidHandle;

	void* data() const { return data_; }
	size_t size() const { return size_; }

	// Platform-specific handle of the buffer.
	Handle handle() const { return handle_; }

	// Integer identifier that can be used used by consumers of DesktopCapturer
	// interface to identify shared memory buffers it created.
	int id() const { return id_; }

	virtual ~SharedMemory() {}

protected:
	SharedMemory(void* data, size_t size, Handle handle, int id);

	void* const data_;
	const size_t size_;
	const Handle handle_;
	const int id_;

private:
	SharedMemory(const SharedMemory&) = delete;
	SharedMemory& operator=(const SharedMemory&) = delete;
};

// Interface used to create SharedMemory instances.
class SharedMemoryFactory {
public:
	SharedMemoryFactory() {}
	virtual ~SharedMemoryFactory() {}

	virtual std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) = 0;

private:
	SharedMemoryFactory(const SharedMemoryFactory&) = delete;
	SharedMemoryFactory& operator=(const SharedMemoryFactory&) = delete;
};

